const express = require('express');
var userController = require('../controller/user.controller');
var loginController = require('../controller/login.controller');

module.exports = (app)=>{
    var router = express.Router();

    router.route('/:username')
        .get(userController.findByUserName);
    router.route('/')
        .get(userController.findAll);

    app.use('/sec/users',router);

    app.route('/login')
        .post(loginController.login);
    app.route('/signout')
        .get(loginController.signOut);

    app.route('/validate')
        .get(function(req,res){
            let user = req.session.user;
            if(user){
                res.json({result:true,data:user});
            }else {
                res.json({result:false,errMsg:'no session'});
            }
        });

    return router;
}